
package com.zzyl.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.zzyl.dto.RoomDto;
import com.zzyl.entity.Room;
import com.zzyl.mapper.RoomMapper;
import com.zzyl.service.BedService;
import com.zzyl.service.RoomService;
import com.zzyl.vo.RoomVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomMapper roomMapper;

    @Autowired
    private BedService bedService;






    /**
     * 根据楼层 id 获取房间视图对象列表
     * @param floorId 楼层 id
     * @return 房间视图对象列表
     */
    @Override
    public List<RoomVo> getRoomsByFloorId(Long floorId) {
       return roomMapper.selectByFloorId(floorId);
    }

    @Override
    public Map<String, Integer> countRoomByTypeName(List<String> collect) {
        if (CollUtil.isEmpty(collect)) {
            return new HashMap<>();
        }
        return roomMapper.countRoomByTypeName(collect);
    }

    @Override
    public List<RoomVo> getRoomsWithNurByFloorId(Long floorId) {
        return roomMapper.selectByFloorIdWithNur(floorId);
    }

    /**
     * 获取所有房间（床位房型）
     * @param floorId
     * @return
     */
    @Override
    public List<RoomVo> getRoomsCheckedByFloorId(Long floorId) {
        return roomMapper.selectRoomsCheckedByFloorId(floorId);
    }

    //添加房间
    @Override
    public void addRoom(RoomDto roomDto) {
        Room room = new Room();
        BeanUtils.copyProperties(roomDto, room);
        room.setCreateTime(LocalDateTime.now());
        roomMapper.addRoom(room);
    }
//删除房间
    @Override
    public void deleteRoom(Long id) {
        roomMapper.deleteRoom(id);
    }
    //查询回显
    @Override
    public RoomVo detRoom(Long id) {
      return   roomMapper.geyRoom(id);
    }
    //修改房间
    @Override
    public void updateRoom(RoomDto roomDto) {
        Room room = new Room();
        BeanUtils.copyProperties(roomDto, room);
        room.setUpdateBy(1l);
        room.setUpdateTime(LocalDateTime.now());
        roomMapper.updateRoom(room);
    }
    //查询所有房间
    @Override
    public List<RoomVo> getAllRoom() {
        List<RoomVo> list = roomMapper.getAllRoom();
        list.stream().map(roomVo -> {
            RoomVo roomVo1 = new RoomVo();
            BeanUtils.copyProperties(roomVo, roomVo1);
            return roomVo1;
        }).collect(Collectors.toList());
        return list;
    }



}

